#ifndef POLYLIST_HPP
#define POLYLIST_HPP
#include <QVector3D>
#include <QtOpenGL>

#include <vector>

static float percentRandom(){
    return rand()%101 / 100.0;
}

static inline QVector3D polygonRandomPoint(const QVector3D &p1, const QVector3D &p2, const QVector3D &p3){
    float rand1 = percentRandom();
    float rand2 = percentRandom();
    float rand3 = percentRandom();
    return( (p1 * rand1 + p2 * rand2 + p3 * rand3)/(rand1+rand2+rand3) );
}

class Polygon3P
{
private:
    QVector3D A,B,C;
public:
    Polygon3P();
    Polygon3P(QVector3D a, QVector3D b, QVector3D c);
    inline QVector3D getA() const { return A; }
    inline QVector3D getB() const { return B; }
    inline QVector3D getC() const { return C; }
	float getSurface() const;
    static QVector3D baryToCart(GLfloat u, GLfloat v, Polygon3P t);
};

class PolyList
{
private:
    std::vector<Polygon3P> polyList;
public:
    PolyList( float * vertices, int * indices, int nb);
    PolyList( std::vector<GLfloat> &verticesArray, std::vector<GLuint> &indicesArray );
    const Polygon3P getPoly(int i) const;
	float getTotalSurface() const;
    inline int getListSize() const {return polyList.size();}
    static std::vector<QVector3D> sceneSampling(PolyList p, int nbOfPoints);
    static std::vector<QVector3D> jitteringPolygon3P(const Polygon3P & p, int nbPoint);
    void addPolygons(float * vertices, int * indices, int nb);
    void addPolygons( std::vector<GLfloat> &verticesArray, std::vector<GLuint> &indicesArray );
};



#endif // POLYLISTE_HPP
